package com.magicborrow.views;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.magicborrow.R;

/**
 * Created by ronaldo on 2016/6/8.
 */
public class StudentDialog extends Dialog{

    public StudentDialog(Context context) {
        this(context,0);
    }

    public StudentDialog(Context context, int themeResId) {
        super(context, R.style.magic_Dialog);

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_stu);
        setDialogSize(0.78d);
        findViewById(R.id.ll_validate).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (listener!=null){
                    listener.clickValidate();
                }
            }
        });
    }

    private OnClickValidete listener;

    public void setOnClickValidete(OnClickValidete listener){
        this.listener=listener;
    }

    public interface OnClickValidete{
        void clickValidate();
    }

    public void setDialogSize(double percent){
        Window window = this.getWindow();
        window.setGravity(Gravity.CENTER);
        Display play = window.getWindowManager().getDefaultDisplay();
        DisplayMetrics metrics = new DisplayMetrics();
        play.getMetrics(metrics);
        WindowManager.LayoutParams params = window.getAttributes();
        params.width=(int) ((metrics.widthPixels)*percent);
        params.height=params.WRAP_CONTENT;
        onWindowAttributesChanged(params);
        window.setAttributes(params);
    }
}
